package com.SFA.FirstPage;

import java.util.Random;

import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;

import android.graphics.Color;

import com.FrameWork.Common.MyApplication;
import com.FrameWork.Utils.DateTimeUtils;
import com.SFA.R;
import com.SFA.Message.MessageLogicManager;

public class HomePageManager {
	
	private static final String[] graphDate = new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
	private static MessageLogicManager manager = new MessageLogicManager();
	
	public static XYMultipleSeriesDataset getBarDemoDataset() {
		XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
		final int nr = 7;
		Random r = new Random();
		for (int i = 0; i < 2; i++) {
			CategorySeries series = new CategorySeries("本周统计");
			for (int k = 0; k < nr; k++) {
				float f = r.nextInt() % 100;
				series.add(100 + f);
			}
			dataset.addSeries(series.toXYSeries());
		}
		return dataset;
	}

	@SuppressWarnings("deprecation")
	public static XYMultipleSeriesRenderer getBarDemoRenderer() {
		XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
		SimpleSeriesRenderer r = new SimpleSeriesRenderer();
		r.setColor(Color.BLUE);
		r.setDisplayChartValues(true);
		renderer.addSeriesRenderer(r);
		r = new SimpleSeriesRenderer();
		r.setColor(Color.GREEN);
		r.setDisplayChartValues(true);
		renderer.addSeriesRenderer(r);
		
		renderer.setChartTitle("销售统计表");
		renderer.setXTitle("日期");
		renderer.setYTitle("值");
		renderer.setXLabels(0);
		renderer.setXAxisMin(0);
		renderer.setXAxisMax(10);   
		renderer.setYAxisMin(0);
		renderer.setYAxisMax(210);
		//Steven jiang 2012/11/23
		//renderer.setBackgroundColor(R.color.white);
		renderer.setApplyBackgroundColor(true);
		renderer.setBarSpacing(0.5f);
		for(int i=1; i<=graphDate.length; i++){
			renderer.addTextLabel(i, graphDate[i-1]);
		}
		return renderer;
	}
	
	/*public static List<NewsEntity> getMessageList(String url, Context context){
		List<MessageEntity> list = manager.getMessageByString(url, context);
		List<NewsEntity> resList = new ArrayList<NewsEntity>();
		if(list.size() > 0){
			for(int i=0; i<list.size(); i++){
				if(i>4)
					break;
				NewsEntity ne = new NewsEntity();
				ne.setNewsTitle(list.get(i).Title);
				ne.setDate(list.get(i).Time);
				ne.setMessageEntity(list.get(i));
				resList.add(ne);
			}
		}
		return resList;
	}*/
	
	/*public static List<NewOrderEntity> getOrderList(Context context){
		List<NewOrderEntity> resList = new ArrayList<NewOrderEntity>();
		List<OrderEntity> list = new OrderManager().LoadToday(context);
		if(list.size() > 0){
			int i = 0;
			for(OrderEntity oe : list){
				if(!getDateDD(oe.REQ_DELIVERY_DATE))
					continue;
				if(i>4)
					break;
				NewOrderEntity noe = new NewOrderEntity();
				noe.setName(oe.NAME);
				noe.setDate(oe.REQ_DELIVERY_DATE);
				noe.setPrice(oe.TOTAL_AMOUNT);
				noe.setOrderEntity(oe);
				resList.add(noe);
				i++;
			}
		}
		return resList;
	}
	*/
	private static boolean getDateDD(String date){
		long d = Long.valueOf(date);
		String dq = DateTimeUtils.GetCurrentTime();
		long f = Long.valueOf(dq);
		if(d >= f){
			return true;
		}else{
			return false;
		}
	}

}
